//package org.znxs.znxsframe.mq_test;
//
//import com.rabbitmq.client.Channel;
//import com.rabbitmq.client.Connection;
//import com.rabbitmq.client.ConnectionFactory;
//
//import java.util.Scanner;
//
//public class DirectProducer {
//
//    // 交换机名称
//    private static final String EXCHANGE_NAME = "direct_znxs";
//
//    public static void main(String[] argv) throws Exception {
//        // 创建连接
//        ConnectionFactory factory = new ConnectionFactory();
//        factory.setHost("localhost");
//        try (Connection connection = factory.newConnection();
//             Channel channel = connection.createChannel()) {
//
//            // 声明交换机类型
//            channel.exchangeDeclare(EXCHANGE_NAME, "direct");
//
//            // 提供消息
//            Scanner scanner = new Scanner(System.in);
//            while (scanner.hasNext()) {
//                String input = scanner.nextLine();
//                String[] strings = input.split(" ");
//
//                if (strings.length < 1) {
//                    continue;
//                }
//                String message = strings[0];
//                String routingKey = strings[1];
//
//                // 发布消息
//                channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes("UTF-8"));
//                System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'");
//            }
//        }
//    }
//}